package com.rongshu.view.mediaPlayer.presenter;

import android.content.Context;

import com.rongshu.api.RetorfitService;
import com.rongshu.utils.Common;
import com.rongshu.utils.UserInfoUtils;
import com.rongshu.view.base.BaseActivity;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.base.mvp.INetView;
import com.rongshu.view.mediaPlayer.bean.AudiobookListResponse;

import java.util.HashMap;
import java.util.Map;

import rx.Subscriber;
import rx.functions.Action0;

/**
 * created by zhengweis on 2019/5/13.
 * description：
 */
public class AudiobookListPresenter extends BasePresenter<INetView> {
    public AudiobookListPresenter(Context context) {
        super(context);
    }

    public void requestAudiobookList() {
        final BaseActivity activity = (BaseActivity) mContext;
        activity.showLoading(true);
        Map<String, Object> map = new HashMap<>();
        map.put("user_id", UserInfoUtils.getUserId());
        RetorfitService.GetAudioArticlesList(UserInfoUtils.getUserId(),
                Common.encryptionSign(map))
                .compose(getView().<AudiobookListResponse>bindToLife()).doOnSubscribe(new Action0() {
            @Override
            public void call() {

            }
        }).subscribe(new Subscriber<AudiobookListResponse>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                activity.showLoading(false);
            }

            @Override
            public void onNext(AudiobookListResponse object) {
                activity.showLoading(false);
                if (object.getErrCode() == 0) {
                    getView().success(object, 0);
                }
            }
        });
    }
}
